home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / FogStyleSample / Source / Misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  1.9 KB  |  104 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*      MISC ROUTINES       */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <Events.h>
  11.  
  12. #include "myglobals.h"
  13. #include "misc.h"
  14.  
  15.  
  16. /****************************/
  17. /*    CONSTANTS             */
  18. /****************************/
  19.  
  20. #define        ERROR_ALERT_ID        401
  21.  
  22. /**********************/
  23. /*     VARIABLES      */
  24. /**********************/
  25.  
  26.  
  27. /****************** DO SYSTEM ERROR ***************/
  28.  
  29. void ShowSystemErr(long err)
  30. {
  31. Str255        numStr;
  32.  
  33.     NumToString(err, numStr);
  34.     DoAlert (numStr);
  35.     CleanQuit();
  36. }
  37.  
  38. /*********************** DO ALERT *******************/
  39.  
  40. void DoAlert(Str255 s)
  41. {
  42.     ParamText(s,NIL_STRING,NIL_STRING,NIL_STRING);
  43.     NoteAlert(ERROR_ALERT_ID,nil);
  44. }
  45.         
  46. /*********************** DO FATAL ALERT *******************/
  47.  
  48. void DoFatalAlert(Str255 s)
  49. {
  50.     ParamText(s,NIL_STRING,NIL_STRING,NIL_STRING);
  51.     NoteAlert(ERROR_ALERT_ID,nil);
  52.     CleanQuit();
  53. }
  54.  
  55. /************ CLEAN QUIT ***************/
  56.  
  57. void CleanQuit(void)
  58. {
  59.     ExitToShell();
  60. }
  61.  
  62.  
  63.  
  64. /******************* FLOAT TO STRING *******************/
  65.  
  66. void FloatToString(float num, Str255 string)
  67. {
  68. Str255    sf;
  69. long    i,f;
  70.  
  71.     i = num;                        // get integer part
  72.     
  73.     
  74.     f = (fabs(num)-fabs((float)i)) * 10000;        // reduce num to fraction only & move decimal --> 5 places    
  75.  
  76.     if ((i==0) && (num < 0))        // special case if (-), but integer is 0
  77.     {
  78.         string[0] = 2;
  79.         string[1] = '-';
  80.         string[2] = '0';
  81.     }
  82.     else
  83.         NumToString(i,string);        // make integer into string
  84.         
  85.     NumToString(f,sf);                // make fraction into string
  86.     
  87.     string[++string[0]] = '.';        // add "." into string
  88.     
  89.     if (f >= 1)
  90.     {
  91.         if (f < 1000)
  92.             string[++string[0]] = '0';    // add 1000's zero
  93.         if (f < 100)
  94.             string[++string[0]] = '0';    // add 100's zero
  95.         if (f < 10)
  96.             string[++string[0]] = '0';    // add 10's zero
  97.     }
  98.     
  99.     for (i = 0; i < sf[0]; i++)
  100.     {
  101.         string[++string[0]] = sf[i+1];    // copy fraction into string
  102.     }
  103. }
  104.